package LeetCode;

public class LC121 {
    public int maxProfit(int[] prices) {
        int tempMin = 1 << 30;
        int ans = 0;
        for (int price : prices) {
            if (price < tempMin) {
                tempMin = price;
            } else {
                ans = Math.max(price - tempMin, ans);
            }
        }
        return ans ;
    }

    public static void main(String[] args) {
        LC121 lc121 = new LC121();
        System.out.println(lc121.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
